<div class="container-fluid" style="padding: 20px 10px 0px 10px">
	<div class="row-fluid">
		<div class="well">
		    <ul class="nav nav-tabs">
		      <li class="active"><b>商品管理</b></li>
		    </ul>
		    <div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="home">
					<form id="formid" action="/goods/addOemGoods" method="post">
						<p>商品名称：<input type="text" value="<?=$getData['goods_title']?>" placeholder="商品名称" style="width:570px" name="goods_title" type='text' class="goods_title"></p>
					
                        <p style="display:inline">销售价格：<input type="text" value="<?=$getData['goods_price']?>" placeholder="销售价格" style="width:120px" name="goods_price" type='text' class="goods_price"> 元 &nbsp;
                            / &nbsp;&nbsp;<input type="text" value="<?=$getData['goods_attr']?>" placeholder="件/个等" style="width:60px" name="goods_attr" type='text' class="goods_attr">&nbsp;
                            <!--成本价格：<input type="text" value="{{$getData.goods_price}}" placeholder="成本价格" style="width:80px" name="channel_price" type='text' class="channel_price" readonly> 元-->
                            <!--&nbsp;盈利预估：<input id="ylz" type="text" style="width: 66px;" disabled value="{{$getData['goods_price']-$getData.channel_price}}" placeholder="盈利预估" name="" class="" /> 元-->
                            &nbsp;品牌：<input type="text" style="width:100px;" name="brands" value="<?=$getData['brand']?>" placeholder="品牌名称" />&nbsp;&nbsp;
                       渠道价：<input type="text" style="width: 80px;" value="<?=$getData['channel_price'] ?: '0.00'?>" placeholder="渠道价格" name="channel_price" class="channel_price"
                        </p>
                        <input type="hidden" value="<?=$getData['goods_full_price']?>" name="goods_full_price" id="goods_full_price" />
                        <input type="hidden" value="<?=$getData['rate']?>" name="ratesnum" id="rates" />

						<p>商品分类： <select style="width:120px" id="setChange" name="cate1_id"></p>
						<?php if($cate){foreach($cate AS $val){?>
						<option value="<?=$val['cate_id']?>" <?=$val['cate_id'] == $getData['cate1_id'] ? 'selected="selected"' : ''?>><?=$val['cate_name']?></option>
						<?php }}else{?>
						<option>没有数据</option>
						<?php }?>
						</select>&nbsp;<select style="width:120px" id="applyIn" name="cate2_id"></select>
						库存：<input type="text" style="width: 80px;" value="{{$getData.kcun}}" placeholder="库存" name="kcun" class="kcun" <if condition="$getData['resource'] neq 0">readonly</if> />
						&nbsp;&nbsp;在线状态：<label style="display:inline"><input type="radio" style="margin-top:1px" name="status" value="0" <if condition="$getData['status'] eq 0">checked</if> /> 下线</label>&nbsp;&nbsp;
						<label style="display:inline"><input type="radio" name="status" style="margin-top:1px" value="1" <if condition="$getData['status'] eq 1">checked</if> /> 上线</label>
						</p>

						<p><div id="setImd" tyimg="square" style="display:inline">商品图片：<input type="text" placeholder="商品图片，必须为正方形，即长宽相等的图片" name="goods_pic" class="setImdText" style="width:416px" value="<?=$getData['goods_pic']?>" readonly> <input type="button" class="btn btn-info setImdBtn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic'] ? transUrl($getData['goods_pic']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
						<p><div id="setImd1" style="display:inline">商品图二：<input type="text" placeholder="商品图片" name="goods_pic2" class="setImd1Text" style="width:416px" value="<?=$getData['goods_pic2']?>" readonly> <input type="button" class="btn btn-info setImd1Btn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic2'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic2'] ? transUrl($getData['goods_pic2']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
						<p><div id="setImd2" style="display:inline">商品图三：<input type="text" placeholder="商品图片" name="goods_pic3" class="setImd2Text" style="width:416px" value="<?=$getData['goods_pic3']?>" readonly> <input type="button" class="btn btn-info setImd2Btn" style='margin-top:-8px' value="选择图片">&nbsp;<a class="btn btn-warning  picViews" <?=$getData['goods_pic3'] ? '' : 'disabled title="暂不可用"'?> url="<?=$getData['goods_pic3'] ? transUrl($getData['goods_pic3']) : ''?>" style='margin-top:-8px'>查看</a></div></p>
						<p><textarea style="width:613px;height:310px;margin-left:73px;margin-top:-20px" name="content"><?=htmlspecialchars_decode($getData['goods_content'])?></textarea></p>
						<input type="hidden" value="<?=$getData['goods_id']?>" name="goods_id" />
						<input type="hidden" value="<?=I('get.vid')?>" name="vid" />
						<input type="hidden" value="1" name="dosubmit" />
					</form>
				</div>
				<div class="btn-toolbar">
				    <button class="btn btn-primary" id="btn-save" style="margin:18px 0 0 70px"><i class="icon-save"></i> 保存发布</button>
				  <div class="btn-group">	
				  </div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$('.goods_hb_price').bind('input onpropertychange',function(){
	//	$('.refer_price').val(($(this).val()/0.7).toFixed(0));
		$.get('/goods/gprice',{'price':$(this).val()},function(data){
			$('.hjfl').val(data.price1);
			$('.byfl').val(data.price2);
			$('.zsfl').val(data.price3);
		},'json');
	}).blur(function(){
		if($(this).val() == '' || $(this).val() == 0){
			$('.hjfl').val('');
			$('.byfl').val('');
			$('.zsfl').val('');
		}
	});
	$('.refer_price').bind('input onpropertychange',function(){
	//	$('.goods_price').val(($(this).val()*0.7).toFixed(0));
		$.get('/goods/gprice',{'price':$('.goods_price').val()},function(data){
			$('.hjfl').val(data.price1);
			$('.byfl').val(data.price2);
			$('.zsfl').val(data.price3);
		},'json');
	}).blur(function(){
		if($(this).val() == ''  || $(this).val() == 0){
			$('.hjfl').val('');
			$('.byfl').val('');
			$('.zsfl').val('');
		}
	});
    $('#plrate,#taxesId').change(function(){
    	if($('.goods_hb_price').val() > 0){
    		doPlus();
    	}else{
    		$('.goods_price,.refer_price').val('');
    	}
    });
    function doPlus(){
    	if($('.goods_hb_price').val() > 0 && $('#plrate').val() > -1){
    		$('#plusIng').show();
        	$.post('/goods/skplus',{'price':$('.goods_hb_price').val(),'lm':$('#plrate').val(),'taxes':$('#taxesId').val()},function(data){
        		$('#plusIng').hide();
    			$('#goods_full_price').val(data.data.goods_full_price);
    			$('.goods_price').val(data.data.goods_price);
    			$('.goods_taxes_price').val(data.data.goods_taxes_price);
    			$('#rates').val(data.data.rates);
    		},'json');
    	}
    }
	$('#btn-save').click(function(){
		if(!($('.goods_title').val())){
			showmsg('商品名称不能为空');
			return false;
		}else if(!($('.goods_price').val())){
			showmsg('销售价格不能为空');
			return false;
		}else if(!($('.goods_attr').val())){
			showmsg('产品规格不能为空');
			return false;
		}else if(!$('.kcun').val()) {
			showmsg('库存不能为空');
			return false;
		}

//		if($('.goods_price').val()<$('.channel_price').val()){
//			showmsg('销售价格不能低于成本价格');
//			return false;
//		}

		<?php if(I('get.vid')!='2'){?>
		if(!$('.hjfl').val()){
			showmsg('黄金返利不能为空');
			return false;
		}<?php }?>else{
			setBtn($('#btn-save'));
			$('#formid').submit();
		}
		
	});
	$('.hjfl').blur(function(){
		if(isNaN($('.hjfl').val())){ 
			$('.hjfl').val('');
		}else{
			$.get('/goods/gprice',{'price':$('#ylz').val()},function(data){
				$('.byfl').val(data.price2);$('.zsfl').val(data.price3);
			},'json');
			mPrice = $('#ylz').val();
		}
	});
	mPrice = '<?=$getData["goods_price"]-$getData["channel_price"]?>';
	setInterval(function checkNum(){
		$('#ylz').val(($('.goods_price').val() - $('.channel_price').val()).toFixed(2));
		if(mPrice - $('#ylz').val() > 0 || $('#ylz').val() - mPrice > 0){
			$.get('/goods/gprice',{'price':$('#ylz').val()},function(data){
				$('.byfl').val(data.price2);
				$('.hjfl').val(data.price1);$('.zsfl').val(data.price3);
			},'json');
			mPrice = $('#ylz').val();
		}
	},100);
	$('.setImdBtn').click(function(){
		$('#setImd').selfups();
	});
	$('.setImd1Btn').click(function(){
		$('#setImd1').selfups();
	});
	$('.setImd2Btn').click(function(){
		$('#setImd2').selfups();
	});
	$('#setChange').change(function(){
		optionHtml = '';
		$.get('/goods/cates',{'ajaxFrom':'1','cateid':$(this).val()},function(data){
			if(data.length){
				for(var i=0;i<data.length;i++){
					optionHtml += '<option value='+data[i].cate_id+'>'+data[i].cate_name+'</option>';
				}
				$('#applyIn').html(optionHtml);
				<?php if($getData['goods_id']){?>
				$('#applyIn').val('<?=$getData["cate2_id"]?>');
				<?php }?>
			}else{
				optionHtml = '<option>没有行业数据</option>';
			}
		},'json');
	}).trigger('change');
})
</script>